# -*- coding: utf-8 -*-
from flask import Flask, request, jsonify, render_template
import jieba
import pandas as pd
import pickle
from settings import path
import warnings

from src.predict_fun import predict

warnings.filterwarnings('ignore')
pd.set_option('display.max_columns', None)

app = Flask(__name__,
            template_folder='templates',  # 自定义模板路径[7,8](@ref)
            static_folder='templates/static'  # 同时指定静态文件路径)
            )


@app.route('/', methods=['GET'])
def home():
    return render_template('index.html')


@app.route('/predict', methods=['POST','GET'])
def predict_api():
    data = request.get_json()
    print(data)
    if not data or 'text' not in data:
        return jsonify({'error': 'No text'}), 400
    # result = {"item": "spam"}
    result = predict(data)
    # print(result)
    return jsonify(result)


if __name__ == '__main__':
    app.run(debug=True,port=5000,host='0.0.0.0')
